package net.assassin.rss.contributors
{
	import mx.collections.ArrayCollection;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	
	import net.assassin.model.contributors.IListContributor;
	import net.assassin.rss.services.DefaultRSSLoadByHTTPSerivce;
	import net.assassin.rss.vo.RSSChannelBase;
	
	/**
	 *  2011-4-7  petersx.g@gmail.com
	 */
	public class RSSListContributor extends RSSChannelBase implements IListContributor
	{
		public function RSSListContributor()
		{
			super();
		}
		
		
		
		
		
		
		
		private var _feed:String;
		
		public function get feed():String
		{
			return _feed;
		}
		
		public function set feed(value:String):void
		{
			_feed = value;
		}
		
		
		
		
		
		
		
		private var _itemContributors:ArrayCollection;

		

		public function get itemContributors():ArrayCollection
		{
			if(_itemContributors == null){
				_itemContributors = new ArrayCollection();
				refresh();
			}
			return _itemContributors;
		}
		
		[Bindable] 
		public function set itemContributors(value:ArrayCollection):void
		{
			_itemContributors = value;
		}
		
		public function refresh():void{
			DefaultRSSLoadByHTTPSerivce.getInstance().load(this.feed,null,"GET",new Object(),successFn,faultFn);
		}
		protected function successFn(result:ResultEvent):void{
			if(_itemContributors){
				
			}
			_itemContributors.removeAll();
			
			
			var xml:XML = new XML(result.token.result);
			
			var tempar:ArrayCollection = buildArticleList(xml);
			_itemContributors.addAll(tempar);
			
		}
		protected function faultFn(fault:FaultEvent):void{
			
		}
		
		public function buildArticleList(result:XML):ArrayCollection{
			var array:Array = [];
			for each(var item:XML in result.channel[0].item){
				var article:RSSItemContributor = new RSSItemContributor();
				/*namespace content = "http://purl.org/rss/1.0/modules/content/";
				use namespace content;*/
				article.title = item.title.toString();
				article.description = item.description;
				//article.content = item.content::encoded.toString();
				array.push(article);
			} 
			
			var source:ArrayCollection = new ArrayCollection(array);
			return source;
		}
		
		
		
		
		
		
		
		private var _uid:uint;
		public var _name:String;
		private var _resource:Class;
		private var _icon:Object;
		
		/*	private var _contextProvider:Class;*/
		
		public function get itemUid():uint
		{
			return _uid;
		}
		
		public function set itemUid(value:uint):void
		{
			_uid = value;
		}
		
		public function get itemName():String{
			return this._name
		}
		[Bindable] 
		public function set itemName(s:String):void{
			this._name = s;
		}
		
		public function get itemResource():Class
		{
			return _resource;
		}
		
		public function set itemResource(value:Class):void
		{
			_resource = value;
		}
		
		public function get itemIcon():Object
		{
			return _icon;
		}
		
		public function set itemIcon(value:Object):void
		{
			_icon = value;
		}
	}
}